package StudyCode.summary.myfile;

import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.FileTime;
import java.util.concurrent.TimeUnit;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class FilterCurrentDay {
	public static void main(String[] args) {
		Path path = Paths.get("E:\\CODE\\JAVA\\ReviewCode\\src\\StudyCode\\summary\\myfile");
		DirectoryStream.Filter<Path> time_filter = new DirectoryStream.Filter<Path>() {

			public boolean accept(Path path) throws IOException {
				long currentTime = FileTime.fromMillis(System.currentTimeMillis()).to(TimeUnit.DAYS);
				long modifiedTime = ((FileTime) Files.getAttribute(path, "basic:lastModifiedTime", LinkOption.NOFOLLOW_LINKS))
						.to(TimeUnit.DAYS);
				return currentTime == modifiedTime;
			}
		};

		try (DirectoryStream<Path> ds = Files.newDirectoryStream(path, time_filter)) {
			for (Path file : ds) {
				System.out.println(file.getFileName());
			}
		} catch (IOException e) {
			System.err.println(e);
		}
	}
}
